var t = wx.createCanvasContext("paintingCanvas"), e = wx.createCanvasContext("sealCanvas");

Page({
    data: {
        choosed: !1,
        timgText: ""
    },
    onLoad: function(a) {
        var n = a.imageUrl;
        this.setData({
            imageUrl: n
        });
        var i = wx.getSystemInfoSync().windowWidth, o = wx.getSystemInfoSync().windowHeight;
        t.drawImage(n, 0, 0, .45 * i, .5 * o), t.draw(), e.drawImage("/images/timg.png", 0, 0, 100, 100), 
        e.draw();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    choosedAct: function() {
        var e = wx.getSystemInfoSync().windowWidth, a = wx.getSystemInfoSync().windowHeight;
        this.setData({
            choosed: !this.data.choosed
        }), t.drawImage(this.data.imageUrl, 0, 0, .45 * e, .5 * a), t.draw(), this.data.choosed && this.certainAct();
    },
    sealInputWord: function(t) {
        var e = t.detail.value;
        this.setData({
            timgText: e
        });
    },
    certainAct: function() {
        var a = this, n = a.data.timgText, i = a.data.imageUrl;
        if (e.setTextAlign("center"), e.setFillStyle("white"), e.drawImage("/images/timg.png", 0, 0, 100, 100), 
        1 == n.length) e.setFontSize(35), e.fillText(n, 50, 58); else if (2 == n.length) e.setFontSize(32), 
        e.fillText(n, 50, 58); else if (3 == n.length) e.setFontSize(30), e.fillText(n, 50, 58); else {
            e.setFontSize(32);
            var o = n.slice(0, 2), s = n.slice(2, 4);
            e.fillText(o, 50, 38), e.fillText(s, 50, 78);
        }
        e.draw();
        var c = wx.getSystemInfoSync().windowWidth, d = wx.getSystemInfoSync().windowHeight;
        wx.canvasToTempFilePath({
            x: 0,
            y: 0,
            width: 100,
            height: 100,
            destWidth: 200,
            destHeight: 200,
            canvasId: "sealCanvas",
            success: function(e) {
                t.drawImage(i, 0, 0, .45 * c, .5 * d), t.drawImage(e.tempFilePath, .45 * c - 40, .5 * d - 40, 30, 30), 
                t.draw(), setTimeout(function() {
                    wx.canvasToTempFilePath({
                        x: 0,
                        y: 0,
                        width: .9 * c,
                        height: d,
                        destWidth: .9 * c * 2,
                        destHeight: 2 * d,
                        canvasId: "paintingCanvas",
                        success: function(t) {
                            a.setData({
                                shareUrl: t.tempFilePath
                            });
                        }
                    });
                }, 1e3);
            }
        });
    },
    sharePainting: function() {
        setTimeout(function() {
            var t = wx.cloud.database().collection("sharePainting"), e = this.data, a = Date.now() + ".png";
            wx.showLoading({
                title: "上传中..."
            }), console.log(e.shareUrl), wx.cloud.uploadFile({
                cloudPath: a,
                filePath: e.shareUrl,
                success: function(e) {
                    t.add({
                        data: {
                            sharePaintingUrl: e.fileID,
                            date: Date.now()
                        },
                        success: function(t) {
                            console.log(t), wx.hideLoading(), wx.showToast({
                                title: "上传成功",
                                icon: "success"
                            }), setTimeout(function() {
                                wx.navigateBack({});
                            }, 1e3);
                        }
                    });
                },
                fail: console.error
            });
        }, 1e3);
    }
});